package com.webdev.service.imp;

import java.util.List;

import com.webdev.dao.RequestDao;
import com.webdev.dao.imp.RequestDaoImp;
import com.webdev.domain.Personnel;
import com.webdev.domain.Request;
import com.webdev.service.RequestService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class RequestServiceImp implements RequestService {
	@Override
	public void addRequest(Request req) {
		RequestDao dao = new RequestDaoImp();
        dao.addRequest(req);
	}
	
	@Override
	public List<Request> bossSearch() {
		RequestDao dao = new RequestDaoImp();
		return dao.bossSearch();
	}
	
	@Override
	public List<Request> staffSearch(Personnel personnel) {
		RequestDao dao = new RequestDaoImp();
		return dao.staffSearch(personnel);
	}
  
	@Override
	public JSONObject getJSONObject(Request req) {
		JSONObject jo = new JSONObject();
		jo.put("rid", req.getRid());
		jo.put("rsdate", req.getRsdate().toString());
		jo.put("redate", req.getRedate().toString());		
		jo.put("rtype", req.getRtype());
		jo.put("rinfo", req.getRinfo());
		jo.put("pid", req.getPid());
		jo.put("rstate", req.getRstate());
		return jo;
	}

	@Override
	public JSONArray getJSONArray(List<Request> reqlist) {
		JSONArray ja = new JSONArray();
    	for (Request req:reqlist) {
    		JSONObject jo = new JSONObject();
    		jo = getJSONObject(req);
    		ja.add(jo);
    	}
		return ja;
	}

	@Override
	public Request getRequestByRid(int rid) {
		RequestDao dao = new RequestDaoImp();
		return dao.getRequestById(rid);
	}

	@Override
	public void updateRequest(Request req) {
        RequestDao dao = new RequestDaoImp();
        dao.updateRequest(req);
	}
	
}
